package com.ambulance.project.biz.controller.manager;

import com.ambulance.common.utils.poi.ExcelUtil;
import com.ambulance.framework.aspectj.lang.annotation.Log;
import com.ambulance.framework.aspectj.lang.enums.BusinessType;
import com.ambulance.framework.web.controller.BaseController;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.page.TableDataInfo;
import com.ambulance.project.manager.domain.BizDriver;
import com.ambulance.project.manager.service.IBizDriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 司机管理Controller
 *
 * @author zr
 * @date 2020-05-12
 */
@RestController
@RequestMapping("/manager/driver")
public class BizDriverController extends BaseController {
    @Autowired
    private IBizDriverService bizDriverService;

    /**
     * 查询司机管理列表
     */
//    //@PreAuthorize("@ss.hasPermi('manager:driver:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizDriver bizDriver) {
        startPage();
        List<BizDriver> list = bizDriverService.selectBizDriverList(bizDriver);
        return getDataTable(list);
    }

    /**
     * 导出司机管理列表
     */
    //@PreAuthorize("@ss.hasPermi('manager:driver:export')")
    @Log(title = "司机管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizDriver bizDriver) {
        List<BizDriver> list = bizDriverService.selectBizDriverList(bizDriver);
        ExcelUtil<BizDriver> util = new ExcelUtil<BizDriver>(BizDriver.class);
        return util.exportExcel(list, "driver");
    }

    /**
     * 获取司机管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manager:driver:query')")
    @GetMapping(value = "/{driverID}")
    public AjaxResult getInfo(@PathVariable("driverID") Long driverID) {
        return AjaxResult.success(bizDriverService.selectBizDriverById(driverID));
    }

    /**
     * 新增司机管理
     */
    //@PreAuthorize("@ss.hasPermi('manager:driver:add')")
    @Log(title = "司机管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizDriver bizDriver) {
        return toAjax(bizDriverService.insertBizDriver(bizDriver));
    }

    /**
     * 修改司机管理
     */
    //@PreAuthorize("@ss.hasPermi('manager:driver:edit')")
    @Log(title = "司机管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizDriver bizDriver) {
        return toAjax(bizDriverService.updateBizDriver(bizDriver));
    }

    /**
     * 删除司机管理
     */
    //@PreAuthorize("@ss.hasPermi('manager:driver:remove')")
    @Log(title = "司机管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{driverIDs}")
    public AjaxResult remove(@PathVariable Long[] driverIDs) {
        return toAjax(bizDriverService.deleteBizDriverByIds(driverIDs));
    }

    /**
     * 冻结司机
     */
    //@PreAuthorize("@ss.hasPermi('manager:driver:query')")
    @PutMapping(value = "light/{driverID}")
    public AjaxResult freeze(@PathVariable("driverID") Long driverID) {
        return AjaxResult.success(bizDriverService.freeze(driverID));
    }

}
